package filesearch.render

import groovy.swing.SwingBuilder

import java.awt.Component;
import javax.swing.JTable
import javax.swing.JLabel
import javax.swing.table.DefaultTableCellRenderer


/**
 * This class render a type of icon depending on the file's suffix
 * 
 * @author mgg
 *
 */
class FileNameRendererByType 
	extends DefaultTableCellRenderer{
	
	@Newify(SwingBuilder)
	public Component getTableCellRendererComponent(JTable table, Object value,
                          boolean isSelected, boolean hasFocus, int row, int column) {
		def label = 
			super.getTableCellRendererComponent(table, value, isSelected, hasFocus,row, column)
		def resource = '/griffon-icon-16x16.png'
		switch (value){
			case ~/.*\.pdf/:
			resource = '/com/famfamfam/silk/icons/page_white_acrobat.png'
			break;
			case ~/.*\.java/:
			resource = '/com/famfamfam/silk/icons/page_white_code.png'
			break;
			case ~/.*\.mp./:
			resource = '/com/famfamfam/silk/icons/music.png'
			break;
		}		
		label.setIcon(SwingBuilder.new().imageIcon(resource: resource))
		return label;
	}
}
